package edu.mju.util;

import java.awt.*;
import java.util.Random;

/**
 * @Author:wyp
 * @Date:2020/4/7 8:46
 */
public class StrUtil {
    /**
     * 获取随机字符串
     * @param count
     * @return 字符串
     */
    public static String randString(int count){
        StringBuilder builder=new StringBuilder();
        String str = "abcdefghijklmnpqrstuvwxy0123456789";
        Random rnd = new Random();
        for(int i=0;i<count;i++) {
            int pos = rnd.nextInt(str.length());
            String s = str.substring(pos, pos + 1);
            builder.append(s);
        }
        return builder.toString();
    }

    /**
     * 获取随机颜色
     * @return color(,,,)
     */
    public static Color getRandomColor(){
        Random random = new Random();
        int red = random.nextInt(256);
        int green = random.nextInt(256);
        int blue = random.nextInt(256);
        return new Color(red,green,blue);
    }

    /**
     * 随机画线
     * @param g
     * @param WIDTH
     * @param HEIGHT
     */
    public static void drawLinetoImg(Graphics g, int WIDTH, int HEIGHT){
        Random de = new Random();
        int x1 = de.nextInt(WIDTH);
        int y1 = de.nextInt(HEIGHT);
        int x2 = de.nextInt(WIDTH);
        int y2 = de.nextInt(HEIGHT);
        g.drawLine(x1, y1, x2, y1);
    }
}
